<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
  onload=()=>{
      //JSON声明
      let user={
          'id':1,
          'name':"刘广",
          'gender':"太监",
          'hobby':["抽烟，喝酒，烫头"],
      };
      //获取JSON中的指定数据
      console.log('id',user['id']);
      console.log('name',user['name']);
      console.log('gender',user['gender']);
      console.log('hobby',user['hobby']);
      //在JSON中添加一条指定数据
      user['age']=28;
      //修改JSON中的数据
      user['id']=438;
      //删除JSON中的数据
      delete user['gender'];
      //遍历JSON数据：只能用for-in来遍历
      for (let key in user) {
          console.log('遍历',key,user[key]);

      }
      //解构JSON
      let {name:username,hobby,sal=5000}=user;
      console.log('name',username);
      console.log('hobby',hobby);
      console.log('sal',sal);
      //全部属性序列化：将JSON中全部的数据变为可传输的字符串
      console.log("全部属性序列化",JSON.stringify(user));
      //部分属性序列化：只序列化name和id属性
      console.log("部分属性序列化",JSON.stringify(user,['nane','id']));
      //反序列化：将JSON格式的字符串变为可操作的数据
      console.log("反序列化",JSON.parse(`{"name":"zhaosi","hobby":"赌博"}`));
  }
</script>
</body>
</html>